package com.wushibo.adddatabackend.controller;

import com.wushibo.adddatabackend.entity.User;
import com.wushibo.adddatabackend.service.impl.UserServiceImpl;
import com.wushibo.adddatabackend.utils.Result;
import com.wushibo.adddatabackend.utils.ResultCode;
import com.wushibo.adddatabackend.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/user")
@Api(value = "User Controller", tags = "用户登录注册接口")
public class UserController {
    @Autowired
    private UserServiceImpl userServiceImpl;
    /**
     * 登录
     */
    @ApiOperation(value = "登录接口", notes = "登录", httpMethod = "GET")
    @RequestMapping("/login")
    public Result login(@RequestParam String account, @RequestParam String password) {
        System.out.println("输出数据，account==>"+account);
        System.out.println("输出数据，password==>"+password);
        String msg = userServiceImpl.loginService(account, password);
        System.out.println("msg==>"+msg);
        if (("success").equals(msg)) {
            System.out.println("输出返回结果===》"+ResultUtil.success("登录成功"));
            return ResultUtil.success("登录成功");
        } else {
            return ResultUtil.error(msg);
        }
    }
    /**
     * 注册
     */
    @ApiOperation(value = "注册接口", notes = "注册", httpMethod = "POST")
    @RequestMapping("/register")
    public Result register(@RequestBody User user){
        String msg=userServiceImpl.registerService(user);

        if(("SUCCESS").equals(msg)){
            return ResultUtil.success("注册成功");
        }else{
            return ResultUtil.error(msg);
        }
    }
}
